package io.renren.modules.sale.service.impl;

import io.renren.modules.sale.service.ISkuInfo;
import org.apache.commons.collections.map.HashedMap;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class SkuInfoImpl implements ISkuInfo {

    private static final String SKU_STATEMENT = "sku.getSkuSaleInfo";

    @Autowired
    SqlSessionTemplate sqlSessionTemplate;

    @Override
    public Map<String, Object> getSkuInfo() {
        List<Map<String, Object>> list = sqlSessionTemplate.selectList(SKU_STATEMENT);
        Map<String, Object> rmp = new HashedMap();
        if (list.size() > 0){
            List<String> key = new ArrayList<>();
            List<String> value = new ArrayList<>();
            for (Map<String, Object> mp : list) {
                key.add(mp.get("dt").toString());
                value.add(mp.get("cnt").toString());
            }
            rmp.put("key", key);
            rmp.put("value", value);
        }
        return rmp;
    }
}
